home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / asm_n_z.arj / RAMADE.ASM < prev    next >
Assembly Source File  |  1987-01-04  |  21KB  |  388 lines

  1. page ,132 ;
  2. title RAMADE - Initialize DOS memory to use segments A,D and E
  3. comment *
  4. ┌──────────────────────────────────────────────────────────────────────────────┐
  5. │           Name: ramade                                                       │
  6. │                                                                              │
  7. │       Function: This program enables the utilization of 192 k of RAM in      │
  8. │                 addition to the 640 k normal maximum for a PC.  The          │
  9. │                 additional RAM must be installed at segment addresses A000,  │
  10. │                 D000 and E000.  The 64k of RAM in segment A is contiguous    │
  11. │                 with the normal 640k and is used simply by extending the     │
  12. │                 memory size above 640.  The 128k in segments D and E is not  │
  13. │                 contiguous with the rest of RAM.  It is used for loading     │
  14. │                 various resident extensions, thus freeing up RAM in the main │
  15. │                 area (0-704k).                                               │
  16. │                                                                              │
  17. │    Description: The memory size is set to the end of segment E by resetting  │
  18. │                 the bios memory size and rebooting.  Storage in segments A,  │
  19. │                 D and E is tested and cleared.  Miscompares are detected,    │
  20. │                 but no attempt is made to handle the more common case of     │
  21. │                 parity checks during the test.                               │
  22. │                                                                              │
  23. │                 Resident extensions are loaded in segments D and E by a      │
  24. │                 secondary command processor which is invoded by RAMADE.      │
  25. │                 After issuing a SETBLOCK function call to free the 128 K     │
  26. │                 bytes in segments D and E, RAMADE invokes the secondary      │
  27. │                 command processor with a command of 'AUTOLOAD'.  This should │
  28. │                 be a bat file which contains the commands to load the        │
  29. │                 resident extensions.                                         │
  30. │                                                                              │
  31. │                 After loading the resident extensions, RAMADE issues other   │
  32. │                 memory management function calls which leave segments B and  │
  33. │                 C allocated and free up unused memory below segment B.       │
  34. │                                                                              │
  35. │                 In addition, the warm boot flag in low storage is reset.     │
  36. │                 The system bios sets this flag when doing a ctl-alt-del      │
  37. │                 reset, but never clears it, apparently relying on power      │
  38. │                 dropping to clear the area.  (I've recently installed 256k   │
  39. │                 chips on my system board, and after this installation,       │
  40. │                 sometimes my system was warm booting when it should have     │
  41. │                 been cold booting after turning the power off briefly.)      │
  42. └──────────────────────────────────────────────────────────────────────────────┘
  43. *
  44. page
  45. comment *
  46. ┌──────────────────────────────────────────────────────────────────────────────┐
  47. │         Inputs: Memory size word in low storage                              │
  48. │                                                                              │
  49. │        Outputs: Memory size word in low storage                              │
  50. │                 Reset flag word in low storage                               │
  51. │                                                                              │
  52. │   Return Codes: First entry - none, exit via reboot.                         │
  53. │                 Second entry - always 0.                                     │
  54. │                                                                              │
  55. │   Dependancies: Low storage areas - see lowstg segment.                      │
  56. │                 GWASMC macros.                                               │
  57. │                 Assumes 832 k installed as described above.                  │
  58. │                 AUTOLOAD bat file invoked.                                   │
  59. │                                                                              │
  60. │  Entry Linkage: Standard COM module invocation                               │
  61. │                                                                              │
  62. │   Exit Linkage: Int 21 function 31 (terminate and remain resident)           │
  63. │                 or reboot via int 19.                                        │
  64. │                                                                              │
  65. │ Change History: Ver  0.00   10/26/85   Under development                     │
  66. │                      1.00   11/03/85   First release                         │
  67. │                      1.10   11/05/85   Changed address equates to table      │
  68. │                      1.20   06/25/86   Save/restore regs around exec cmd     │
  69. │                                        processor for DOS 2.1 bug             │
  70. │                      1.21   12/05/86   Zap mem alloc table from "M" to "Z"   │
  71. │                                        This make DOS forget about discontig. │
  72. └──────────────────────────────────────────────────────────────────────────────┘
  73. *
  74. page
  75. ;══════════════════════════════════════════════════════════════════════════════
  76. ; Get Macros and other standard setups
  77. ;──────────────────────────────────────┐
  78. if1                                    ;
  79. include gwasmc.mac                     ;
  80. endif                                  ;
  81. .radix   16                            ;
  82.                                        ;────────────────────────────────────────
  83. ;═══════════════════════════════════════════════════════════════════════════════
  84. ; Map low storage
  85. ;──────────────────────────────────────┐
  86. lowstg   segment  at 0                 ;
  87.          org      413                  ;
  88. mem_size dw                            ; Memory size in K, set by bios and us
  89.          org      472                  ;
  90. rst_flag dw                            ; Reset flag - set to 1234 by bios to
  91.                                        ; indicate warm boot in process.
  92. lowstg   ends                          ;
  93.                                        ;────────────────────────────────────────
  94. page
  95. ;═══════════════════════════════════════════════════════════════════════════════
  96. ; Global data segment entries and equates
  97. ;──────────────────────────────────────┐
  98. cgroup   group    codeseg,dataseg      ;
  99. dataseg  segment  'data'               ;
  100.                                        ;
  101.          db       'RAMADE  1.21 - IBM Internal Use Only ',0dh,0a
  102.          db       'Cornell Wright - WRIGHT at PKEDVM8 ',0dh,0a
  103.                                        ;
  104.                                        ;
  105. if ($-dataseg) mod 10h                 ; align to paragraph boundry
  106.          org      ($-dataseg)+10h-(($-dataseg) mod 10h)
  107. endif                                  ;
  108.                                        ;
  109.          db       'ADDR TAB'           ;
  110. mconend  dw       0b000          ; +00   End of contiguous memory (para addr)
  111. mdissta  dw       0d000          ; +02   Start of discontiguous memory
  112. mdisend  dw       0f000          ; +04   End of discontiguous memory
  113.                                  ;
  114. mseg1    dw       0a000          ; +06   First segment to clear and test
  115. mseg1l   dw       08000          ; +08   First segment length in words
  116.                                  ;
  117. mseg2    dw       0d000          ; +0a   Second  "           "
  118. mseg2l   dw       08000          ; +0c     "     "           "
  119.                                  ;
  120. mseg3    dw       0e000          ; +0e   Third   "           "
  121. mseg3l   dw       08000          ; +10     "     "           "
  122.                                        ;
  123. dataseg  ends                          ;
  124. ;──────────────────────────────────────┘
  125. ; PSP
  126. ;──────────────────────────────────────┐
  127. codeseg  segment  'code'               ;
  128. psp      label    byte                 ; Program Segment Prefix
  129. pspint   dw       ?                    ; Int 20H for return
  130.          org      2c                   ;
  131. pspenv   dw       ?                    ; Segment address of the Environment
  132.          org      80                   ;
  133. pspparm  db       80 dup(?)            ; Input parameters
  134.          ORG      80                   ;
  135. pspparmn db       ?                    ; Number of Characters
  136. pspparmt db       7f dup(?)            ; Text of input parameters
  137.                                        ;────────────────────────────────────────
  138. page
  139. ;═══════════════════════════════════════════════════════════════════════════════
  140. ; Entry - clear reset flag & check for pass a or b.
  141. ;──────────────────────────────────────┐
  142.          assume   cs:cgroup,ds:cgroup,es:cgroup,ss:cgroup
  143. entry:                                 ;
  144.          dosentry COMPGM               ;
  145.          xor      ax,ax                ; get addressability to lowstg
  146.          mov      ds,ax                ;
  147.          assume   ds:lowstg            ;
  148.                                        ;
  149.          mov      rst_flag,0000        ; clear reset flag
  150.                                        ;
  151.          mov      ax,mdisend           ; compare memory size to end
  152.          mov      cl,6                 ; convert from seg addr to number of k
  153.          shr      ax,cl                ;
  154.          cmp      ax,mem_size          ;
  155.          ljmp     e,pass_b             ; it's equal - this is the second pass
  156.                                        ;
  157.                                        ;────────────────────────────────────────
  158. ;═══════════════════════════════════════════════════════════════════════════════
  159. ; Pass A - adjust memory size, test and clear extra ram, reboot
  160. ;──────────────────────────────────────┐
  161. pass_a:                                ;
  162.          mov      mem_size,ax          ; set memory size to end
  163.                                        ;
  164.          mov      ax,cs                ; reestablish ds
  165.          mov      ds,ax                ;
  166.          assume   ds:cgroup            ;
  167.                                        ;
  168.          mov      ax,mseg1             ; test and clear segments a,d & e
  169.          mov      bx,mseg1l            ;
  170.          call     testmem              ;
  171.          mov      ax,mseg2             ;
  172.          mov      bx,mseg2l            ;
  173.          call     testmem              ;
  174.          mov      ax,mseg3             ;
  175.          mov      bx,mseg3l            ;
  176.          call     testmem              ;
  177.                                        ;
  178.          int      19                   ; reboot
  179.                                        ;────────────────────────────────────────
  180. page
  181. ;═══════════════════════════════════════════════════════════════════════════════
  182. ; Testmem - checkout memory area pointed to by ax, word len in bx
  183. ;──────────────────────────────────────┐
  184. testmem  proc                          ;
  185.                                        ;
  186. dataseg  segment                       ;
  187. testmsg  db       'RAMADE00 - Testing RAM in segment '
  188. segchar  db                            ;
  189.          db       '000.',0dh,0ah,'$'   ;
  190. dataseg  ends                          ;
  191.                                        ;
  192.          cmp      bx,0                 ; if count 0, get out
  193.          jne      continue             ;
  194.          ret                           ;
  195.                                        ;
  196. continue:push     es                   ; save es
  197.          mov      es,ax                ;
  198.                                        ;
  199.          mov      cl,0c                ; Convert seg addr to ascii
  200.          shr      ax,cl                ;   and write message.
  201.          cmp      al,09                ;
  202.          jle      noadj                ;
  203.          add      al,7                 ;
  204. noadj:   add      al,30                ;
  205.          mov      segchar,al           ;
  206.          wto      testmsg              ;
  207.                                        ;
  208.          cld                           ; test and clear memory segment
  209.                                        ;
  210.          mov      ax,05a6dh            ; pattern = 5A6D
  211.          mov      di,0                 ;
  212.          mov      cx,bx                ;
  213.          rep      stosw                ;
  214.          mov      di,0                 ;
  215.          mov      cx,bx                ;
  216.          repe     scasw                ;
  217.          jne      miscomp              ;
  218.                                        ;
  219.          mov      ax,0a55ah            ; pattern = A55A
  220.          mov      di,0                 ;
  221.          mov      cx,bx                ;
  222.          rep      stosw                ;
  223.          mov      di,0                 ;
  224.          mov      cx,bx                ;
  225.          repe     scasw                ;
  226.          jne      miscomp              ;
  227.                                        ;
  228.          mov      ax,06da5h            ; pattern = 6DA5
  229.          mov      di,0                 ;
  230.          mov      cx,bx                ;
  231.          rep      stosw                ;
  232.          mov      di,0                 ;
  233.          mov      cx,bx                ;
  234.          repe     scasw                ;
  235.          jne      miscomp              ;
  236.                                        ;
  237.          mov      ax,0000              ; clear to 0000
  238.          mov      di,0                 ;
  239.          mov      cx,bx                ;
  240.          rep      stosw                ;
  241.                                        ;
  242.          pop      es                   ;
  243.          ret                           ;
  244.                                        ;
  245. miscomp: pop      es                   ;
  246.          jmp      errmc                ;
  247.                                        ;
  248. testmem  endp                          ;
  249.                                        ;────────────────────────────────────────
  250. page
  251. ;═══════════════════════════════════════════════════════════════════════════════
  252. ; Pass B - free discontiguous memory, load resident pgms and free remaining ram.
  253. ;──────────────────────────────────────┐
  254. pass_b:                                ;
  255.          push     es                   ; reestblish local data segment
  256.          pop      ds                   ;
  257.          assume   ds:cgroup            ;
  258.          mov      bx,mdissta           ; Issue SETBLOCK to free memory in
  259.          mov      ax,es                ; discontiguous area
  260.          sub      bx,ax                ;
  261.          setblock ,,errsb1             ;
  262. ;──────────────────────────────────────┘
  263. ; Find COMSPEC= in environment
  264. ;──────────────────────────────────────┐
  265. dataseg  segment                       ;
  266. scanfor  db       'COMSPEC='           ; environment string to scan for
  267. scanfore equ      $                    ;
  268. scanlen  equ      scanfore-scanfor     ; length of scanfor
  269. dataseg  ends                          ;
  270.                                        ;
  271.          cld                           ;
  272.          mov      al,0                 ;
  273.          mov      di,0                 ;
  274.          mov      es,pspenv            ; es:di points to environment
  275.          assume   es:nothing           ;
  276. envloop: mov      si,offset cgroup:scanfor; ds:si points to string to match
  277.          mov      cx,scanlen           ;
  278.          repe     cmpsb                ; scan for a match
  279.          je       found                ; if equal, we found it
  280.          sub      di,1                 ; no - look for end of string (00)
  281.          mov      cx,0ffff             ;
  282.          repne    scasb                ; find 1st 0 at or after miscompare
  283.          cmp      es:byte ptr[di],0    ; if followed by another 0 then at end
  284.          jne      envloop              ; not 0 - go check next string
  285.          jmp      errnocs              ; err msg & get out
  286.                                        ;
  287. found:   push     es                   ; swap es & ds so es:di points to string
  288.          push     ds                   ;
  289.          pop      es                   ;
  290.          pop      ds                   ;
  291.          assume   ds:nothing,es:cgroup ;
  292.          mov      dx,di                ;
  293. page
  294. ;──────────────────────────────────────┘
  295. ; Invoke command.com to run autoload.bat
  296. ;──────────────────────────────────────┐
  297. dataseg  segment                       ;
  298. loadcmd  db       loadcmde-loadcmd-1   ; cmd string for 2ndary cmd processor
  299.          db       '/c autoload',0dh;   ;
  300. loadcmde equ      $                    ;
  301.                                        ;
  302. lcb      label    byte                 ; load control block
  303. lcbenv   dw       0                    ; address of passed environment
  304. lcbcmd   dd                            ; address of command string
  305. lcbfcb1  dd       0                    ; address of fcb1
  306. lcbfcb2  dd       0                    ; address of fcb2
  307. dataseg  ends                          ;
  308.                                        ;
  309.          mov      bx,offset cgroup:lcb ;
  310.          mov      lcbcmd,offset cgroup:loadcmd
  311.          mov      lcbcmd+2,es          ;
  312.          mov      al,0                 ;
  313.          doscall  4bh                  ;
  314.                                        ;
  315.          mov      ax,cs                ; restore seg regs for dos 2.1 bug
  316.          mov      ss,ax                ;
  317.          mov      ds,ax                ;
  318.          mov      es,ax                ;
  319.          assume   cs:cgroup,ds:cgroup,es:cgroup,ss:cgroup
  320.                                        ;
  321.          ljmp     c,errexec            ; check for error
  322. ;──────────────────────────────────────┘
  323. ; Free and reallocate 'missing' ram
  324. ;──────────────────────────────────────┐
  325.                                        ;
  326.          mov      bx,mconend           ; Issue SETBLOCK to free memory in
  327.          mov      ax,es                ; missing area
  328.          sub      bx,ax                ;
  329.          dec      bx                   ;
  330.          setblock ,,errsb2             ;
  331.                                        ;
  332.          mov      bx,mdissta           ; Issue GETBLOCK to reallocate
  333.          sub      bx,mconend           ; missing area
  334.          getmain  ,,errgm              ;
  335.          cmp      ax,mconend           ;
  336.          ljmp     ne,errwrad           ;
  337.                                        ;
  338.          freemain pspenv               ; free environment
  339.                                        ;
  340.          push     es                   ;
  341.          mov      ax,ds                ; set es to segment of mem alloc block
  342.          sub      ax,1                 ;
  343.          mov      es,ax                ;
  344.          cmp      byte ptr es:[0],byte ptr "M"
  345.          ljmp     ne,errnotm           ; if the first char is a "M", set to
  346.          mov      es:byte ptr[0],"Z"   ; the discontiguous memory.
  347.          pop      es                   ;
  348.                                        ;
  349.          dosexit  ,0                   ; terminate & remain resident, but free
  350.                                        ; entire pgm area.
  351.                                        ;────────────────────────────────────────
  352. page
  353. ;═══════════════════════════════════════════════════════════════════════════════
  354. ; Error messages and exit
  355. ;──────────────────────────────────────┐
  356. errmc:                                 ;
  357.          wto      'RAMADE01: Error - storage miscompare.'
  358.          jmp      exit                 ;
  359. errsb1:                                ;
  360.          wto      'RAMADE02: Error - from 1st SETBLOCK.'
  361.          jmp      exit                 ;
  362. errnocs:                               ;
  363.          wto      'RAMADE03: Error - COMSPEC= not found.'
  364.          jmp      exit                 ;
  365. errexec:                               ;
  366.          wto      'RAMADE04: Error - from EXEC.'
  367.          jmp      exit                 ;
  368. errsb2:                                ;
  369.          wto      'RAMADE05: Error - from 2nd SETBLOCK.'
  370.          jmp      exit                 ;
  371. errgm:                                 ;
  372.          wto      'RAMADE06: Error - from GETMAIN.'
  373.          jmp      exit                 ;
  374. errwrad:                               ;
  375.          wto      'RAMADE07: Error - wrong address returned by GETMAIN.'
  376.          jmp      exit                 ;
  377. errnotm:                               ;
  378.          wto      'RAMADE08: Error - memory alloc block not found.'
  379.          jmp      exit                 ;
  380. page
  381. ;──────────────────────────────────────┘
  382. ; Exit
  383. ;──────────────────────────────────────┐
  384.          dosexit  exit                 ;
  385. codeseg  ends                          ;
  386.          end      entry                ;
  387.                                        ;────────────────────────────────────────
  388.